/*
 * RouteSettings.h
 *
 *  Created on: Jan 20, 2011
 *      Author: Kevin Mueller
 */

#ifndef ROUTINGSERVICE_H_
#define ROUTINGSERVICE_H_

#include "Helpers.h"

#include "PositioningSystem.h"

#include "../core/Opennav.h"

#include <QObject>
#include <QThread>
#include <QMutex>
#include <QGeoCoordinate>


class RouteSettings : public QObject{
	Q_OBJECT

public:
	RouteSettings(QObject* parent = 0);
	LabeledCoordinate getOrigin() const;
	LabeledCoordinate getDestination() const;
	int getPreferredRoute() const;
	bool isAvoidHighways() const;
	bool isAvoidTollroads() const;

public slots:
	void reset();
	void setOrigin(const LabeledCoordinate &c);
	void setDestination(const LabeledCoordinate &c);
	void setPreferredRoute(int val);
	void avoidHighways(int val);
	void avoidHighways(bool val);
	void avoidTollroads(int val);
	void avoidTollroads(bool val);

private:
	LabeledCoordinate origin;
	LabeledCoordinate destination;
	int preferredRoute;
	bool avoidHighways_;
	bool avoidToll_;
};

class RoutingService : protected QThread{
	Q_OBJECT

public:
	RoutingService(opennav::Map* map);
	void setSettings(const RouteSettings* s);
	int getRemainingTavelTime(const ExtendedGeoPositionInfo* gps);
	int getRemainingDistance(const ExtendedGeoPositionInfo* gps);

public slots:
	bool calculate();
	void stop();

signals:
	void noRoute();
	void startNavigation();
	void stopNavigation();

private:
	void run();

	const RouteSettings* settings;
	opennav::Map* map;
	QMutex mutex;
};

#endif /* ROUTESETTINGS_H_ */
